
<script type="text/javascript" src="components/nguoiban/user.js"></script>

<div class="art-post">
                                <div class="art-post-tl"></div>
                                <div class="art-post-tr"></div>
                                <div class="art-post-bl"></div>
                                <div class="art-post-br"></div>
                                <div class="art-post-tc"></div>
                                <div class="art-post-bc"></div>
                                <div class="art-post-cl"></div>
                                <div class="art-post-cr"></div>
                                <div class="art-post-cc"></div>
                                <div class="art-post-body">
                            <div >
                                            <div class="art-postmetadataheader">
                                                <h2 class="art-postheader">
                                                    <img src="images/postheadericon.png" width="32" height="32" alt="postheadericon" />
                                                    Đăng Ký Tài Khoản Người Bán
                                                </h2>
                                            </div>
                                            <div class="art-postcontent">
                                                <!-- article-content -->
 
<?php 
	include_once('class_nguoiban.php');
	include_once('library/MailPackage/sendmail.php');
?> 

<?php
	$LoiCode ="";
	$LoiUserName = "";
	$LoiEmail ="";
	
	$tendangnhap= '';
	$matkhau = '';
	$email= '';
	$reemail= '';
	$hoten = '';
	$ngay = date('d');
	$thang = date('m');
	$nam = date('y');
	$diachi = '';
	$dienthoai = '';	
	$gioitinh = 1;
	$hinhanh = 'nopic.gif';
	
	$Type = 0;
	if(isset($_REQUEST['Type']))
		$Type = $_REQUEST['Type'];
	
	if ( $Type == 1 )
	{
		$tendangnhap = $_REQUEST["tendangnhap"];
		$matkhau =  $_REQUEST["matkhau"];
		$email = $_REQUEST['email'];
		$hoten = $_REQUEST['hoten'];
		$ngay = $_REQUEST['ngay'];
		$thang = $_REQUEST['thang'];
		$nam = $_REQUEST['nam'];
		$diachi = $_REQUEST['diachi'];
		$dienthoai = $_REQUEST['dienthoai'];
		$gioitinh = $_REQUEST['gioitinh'];
//		$hinhanh = $_REQUEST['hinhanh'];
//		$hinhanh = "images/thanhvien/".$hinhanh;

		$code = $_REQUEST["code"];
	
		
		$tendangnhap = strtolower($tendangnhap);
		$flag = 1;	
		$tv_user = new class_nguoiban();
		$row_user = $tv_user->KiemTraTonTaiUserName($tendangnhap);

		if($row_user != NULL)
		{
			$LoiUserName = "Tài khoản đã có người sử dụng";
			$flag = 0;
		}
		
		$tv_email = new class_nguoiban();
		$row_email = $tv_email->KiemTraTonTaiEmail($email);
		if($row_email != NULL)
		{
			$LoiEmail = "Email đã có người sử dụng";
			$flag = 0;
		}
			
		if(!isset($_SESSION["security_code"]) || $_SESSION["security_code"] != $code)
		{
			$LoiCode ="Kí tự không khớp với hình";
			$flag = 0;
		}
		
		// mật khẩu
		if($flag == 1)
		{
			$matkhau = $_REQUEST['matkhau'];
			$matkhau = md5($matkhau) ;
			
			$stringdate = $nam.'-'.$thang.'-'.$ngay ;
			$ngaysinh = date($stringdate) ;
			
			$md5_hash = md5(rand(0,999)); // phat sinh ma kich hoat	
			$activecode = substr($md5_hash, 15, 20); 
	
			
			$tv_add = new class_nguoiban();
			$mauser = $tv_add->themmoi($tendangnhap,$matkhau,$email,$hoten,$diachi,$dienthoai,$gioitinh,$ngaysinh,$hinhanh);
			
			if($mauser != null)
			{
				//------ send mail -------------------------------------
				$kqsend = sendmail($email , $mauser ,$activecode);
				if($kqsend == 0)
				{
					echo "<div style='color:red'>Không gửi được mail ! ! !</div>";
					exit();
				}	
				
				
				echo "<meta http-equiv='refresh' content='0;url=index.php?com=nguoiban&fun=loginsuccess&type=1&$kqsend' />";
			}
			else
			{
				echo "<div style='color:red'>Đăng ký thất bại !</div>";
			}
		}	
	}
?>
    
    <?php 
		echo "<div style='color:red' align='left'> 
			 $LoiUserName
   			 $LoiEmail
     		 $LoiCode 
			 </div>"; 
	?>
    
	<table class='sample' align="center">
		  <tr>
			<td>Tên Đăng Nhập</td>
			<td><input id='addTenDangNhap' name='addTenDangNhap' type='text' value='<?php echo $tendangnhap ?>' onkeyup='ktuser()';/>(*)</td>
			<td><div id='loitendangnhap'></div></td>
		  </tr>
		   <tr>
			<td>&nbsp;</td>
			<td colspan='2' align='center'>Tên đăng nhập phải gồm kí tự a->z,0->9.</td>
		  </tr>
		   <tr>
			<td>Mật Khẩu</td>
			<td><input id='addMatKhau' name='addMatKhau' type='password' onkeyup='ktmatkhau1()';/>(*)</td>
			<td><div id='loimatkhau'></div></td>
		  </tr>
		  <tr>
			<td>Nhắc lại Mật Khẩu</td>
			<td><input id='addReMatKhau' name='addReMatKhau' type='password' onkeyup='ktmatkhau2()';/>(*)</td>
			<td><div id='loairematkhau'></div></td>
		  </tr>
		   <tr>
			<td>&nbsp;</td>
			<td colspan='2' align='center'>Mật khẩu phải nhiều hơn 6 kí tự</td>
		  </tr>
		  <tr>
			<td>Email</td>
			<td><input id='addEmail' name='addEmail' type='text' value='<?php echo $email ?>' onkeyup='ktemailhople();'/>(*)</td>
			<td><div id='loiemail'></div></td>
		  </tr>
		  <tr>
			<td>Nhắc lại Email</td>
			<td><input id='addReEmail' name='addReEmail' type='text' value='<?php echo $reemail ?>' onkeyup='ktkhopemail();'/>(*)</td>
			<td><div id='loireemail'></div></td>
		  </tr>
		  <tr>
			<td colspan='3'>&nbsp;</td>
		  </tr>
		  <tr>
			<td>Họ tên</td>
			<td><input id='addHoTen' name='addHoTen' type='text' value='<?php echo $hoten ?>' onkeyup='kthoten();'/>(*)</td>
			<td><div id='loihoten'></div></td>
		  </tr>
		  <tr>
			<td>Địa Chỉ</td>
			<td><input id='addDiaChi' name='addDiaChi' type='text' value='<?php echo $diachi ?>'/></td>
			<td>&nbsp;</td>
		  </tr>		  
		 <tr>
			<td>Điện Thoại</td>
			<td><input id='addDienThoai' name='addDienThoai' type='text' value='<?php echo $dienthoai ?>' onkeyup='ktdienthoai();'/></td>
			<td><div id='loidienthoai'></div></td>
		  </tr>
		   <tr>
			<td>Giới tính</td>
			
				<td><input id='addGioiTinh' name='addGioiTinh' type='radio' checked='checked' value='Nam'/>Nam &nbsp;
				<input id='addGioiTinh' name='addGioiTinh' type='radio' value='Nu'/>	Nữ</td> 
		<td>&nbsp;</td>
		  </tr>
		   <tr>
			<td>Ngày sinh</td>
            <?php 
				echo "<td>
				<select name='ngay' id='ngay' >";
					for($i = 1 ; $i<=31 ; $i++)
					{
						if($ngay == $i )
							echo "<option value='$i' selected='selected'>$i</option>";
						else
							echo "<option value='$i'>$i</option>";
					}
				echo "</select>";
				echo "&nbsp;&nbsp;";
				echo "<select name='thang' id='thang' >";
					for( $i = 1 ; $i<=12 ; $i++)
					{
						if($thang == $i )
							echo "<option value='$i' selected='selected'>$i</option>";
						else
							echo "<option value='$i'>$i</option>";
					}					
				echo "</select>";
				echo "&nbsp;&nbsp;";
				echo "<select name='nam' id='nam' >";	
					for($i = date('Y') ; $i>1929 ; $i--)
					{
						if($nam == $i )
							echo "<option value='$i' selected='selected'>$i</option>";
						else
							echo "<option value='$i'>$i</option>";
					}
					//<img src="images/static.jpg"/>
					//
				?>
				</select>
				</td>
			<td>&nbsp;</td>
		  </tr>

		  
		  <tr><td colspan='3'>&nbsp;</td></tr>
			<tr>
				<td></td>
				<td><img src="components/nguoiban/captcha.php" id='captcha' alt='captcha'/>
				</td>
                <td>&nbsp;</td>
			</tr>
			<tr>	
				<td></td>
				<td><label for='security_code'><strong></p>Vui lòng điền các kí tự trong hình trên</strong></label></td>
                <td>&nbsp;</td>
			</tr>
			<tr>
				<td></td>
				<td><input type='text' id='security_code' name='security_code' autocomplete='off' onkeyup='KiemTraCode()'/>(*)</td>
				<td><div id='ErrorCode'></div></td>
			</tr>		
		</table>	
        
       
	<div align="center">
	<br />
    <a href=index.php?com=nguoiban&fun=dangky><input type='button' name='New' value='Làm lại' /></a>
	&nbsp;&nbsp;&nbsp;<input type='submit' name='Add' value='Đăng ký' onclick='kiemtradangki()' />
    </div>                                     
                                                
                                                
                                                    
                                                <!-- /article-content -->
                                            </div>
                                            <div class="cleared"></div>
                            </div>
                            
                            		<div class="cleared"></div>
                                </div>
                            </div>